package zr.util;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

import zr.Main;

public class UIExtends {
     public static void main(String[] args) {
         JFrame frame=new JFrame();
         frame.setSize(600,400);
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         GridLayout gl=new GridLayout(5,5,0,10);
         frame.setLayout(gl);
         //Flash Component Example;
         JPanel pane1=new JPanel();
         final JButton btnFlash=new JButton("��˸");
         final JLabel lb=new JLabel("Hello!");
         final JComboBox cb=new JComboBox(new Object[]{"111","222","333"});
         lb.setOpaque(true);
         lb.setBorder(BorderFactory.createBevelBorder(1));
         btnFlash.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 flashComponent(lb,Color.yellow,200);
                 flashComponent(btnFlash,Color.red,400);
                 flashComponent(cb,Color.blue,600);
             }
         });
         pane1.setBorder(BorderFactory.createTitledBorder("��˸�ؼ�����"));
         pane1.add(lb);
         pane1.add(cb);
         pane1.add(btnFlash);
         frame.add(pane1);

         frame.setVisible(true);
     }
     static boolean shouldStop=false;
     public static void flashComponent(final Component comp,final Color flashColor,final int flashSpan){
    	
         Thread th = new Thread() {
             public void run() { 
            	 shouldStop=false;
                 Color orgColor = comp.getBackground();
                 while(true) {
                	 if(shouldStop==true){
                		 shouldStop=false;
                		 break;
                	 }
                     Color col = comp.getBackground();
                     if(col==orgColor)
                         comp.setBackground(flashColor);
                     else
                         comp.setBackground(orgColor);
                     //System.out.println("Set Color "+comp.getBackground());
                     try {
                         Thread.sleep(flashSpan);
                     } catch (InterruptedException ex) {
                         ex.printStackTrace();
                     }
                 }
                 comp.setBackground(orgColor);
             }
         };
         th.start();
     }
     public static void unflash(final Component comp){

    	 shouldStop=true;
     }
}
 

